package org.singledog.permission.exception;

import lombok.Data;
import lombok.Getter;

/**
 * Permission异常持有类，{@link PermissionException}
 *
 * @author liuzheming
 * @since 2021.9.18
 */
@Getter
public enum PermissionExceptionHolder {

    /**
     * 没有登录
     */
    NO_LOGIN(new PermissionException(401, "sorry,you are not login.")),

    /**
     * 没有权限
     */
    NO_AUTHORIZATION(new PermissionException(401, "sorry,you don't have the permission to visit this resource.")),

    /**
     * token过期
     */
    TOKEN_TIME_OUT(new PermissionException(401, "sorry,your token is timeout."));

    private PermissionException permissionException;

    PermissionExceptionHolder(PermissionException permissionException) {
        this.permissionException = permissionException;
    }

    @Data
    public static class PermissionException extends RuntimeException {

        private int code;

        public PermissionException(int code, String message) {
            super(message);
            this.code = code;
        }
    }
}
